package cn.bqjr.eily.core.annotation;

import cn.bqjr.eily.core.serializer.JacksonFieldKVSerializer;
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.lang.annotation.*;

/**
 * jackson KV转换
 * 在需要转换为Value的字段上加上本注解
 *
 * @author hillfly
 */
@Inherited
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside
@JsonSerialize(using = JacksonFieldKVSerializer.class)
public @interface TransferKV {

    enum KvType {
        DICT, CUSTOM, USER
    }

    /**
     * 目标值来源类型，DICT-字典表sys_dict，USER-用户表sys_user, CUSTOM-自定义表
     * 默认：DICT
     * @return
     */
    KvType kvType() default KvType.DICT;

    /**
     * 目标值字典类型，仅当kvType为KvType.DICT时有效
     * @return
     */
    String codeType() default "";

    /**
     * 目标值来源表名，仅当kvType为KvType.CUSTOM时有效
     * @return
     */
    String table() default "sys_dict";

    /**
     * 目标值key对应列名，仅当kvType为KvType.CUSTOM时有效
     * @return
     */
    String keyColumn() default "dictKey";

    /**
     * 目标值value对应列名，仅当kvType为KvType.CUSTOM时有效
     * @return
     */
    String valueColumn() default "dictValue";

}
